
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../http/api.dart';
import '../../main.dart';
import '../circle_progress_widget.dart';
import '../focus_killer.dart';

class PersonModel{

  RxBool isEmpty = RxBool(false);

  _checkFace() {
    faceQuery(currentTask.uid).then((value){
      isEmpty.value = value;
    });
  }

  show({showFaceAuth = false,callback}){
    if(showFaceAuth){
      _checkFace();
    }
    return Container(
        margin: EdgeInsets.only(left: 4.w,right: 4.w),
        height: 130.h,
        width: double.infinity,
        decoration: const BoxDecoration(
          image: DecorationImage(
            fit: BoxFit.fill,
            image: AssetImage(
              "assets/images/person_info_bg.png",
            ),
          ),
        ),
        child: Stack(
          alignment: AlignmentDirectional.centerStart,
          children: [
            focusKiller(),
            Positioned(left:50.w,child: Image.asset("assets/images/head.jpg",width: 60.w,fit: BoxFit.fitWidth,),),
            Positioned(left:130.w,top:45.h,child: Text("${currentTask.uName}",style: TextStyle(color: Colors.blue,fontSize: 12.sp,fontWeight: FontWeight.bold),),),
            Positioned(left:130.w,top:67.h,child: Text("读者证号:${currentTask.uid}",style: TextStyle(color: Colors.blue,fontSize: 10.sp,fontWeight: FontWeight.bold),),),
            Positioned(
                right: 30.w,
                child: Stack(
                  alignment: Alignment.center,
                  children: [
                    CircleProgress(size: 60.w,strokeWidth: 3.w,percent: currentTask.readerEntity!.currentBorrowCount!/currentTask.readerEntity!.limitCount!,color: Colors.blue,),
                    Container(
                      width: 50.w,
                      height: 50.w,
                      decoration: BoxDecoration(
                        color: Colors.blue,
                        borderRadius: BorderRadius.all(Radius.circular(25.r)),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text('${currentTask.readerEntity!.currentBorrowCount}/${currentTask.readerEntity!.limitCount}',style: TextStyle(color: Colors.white,fontSize: 10.sp,fontWeight: FontWeight.bold),),
                          Text('借阅数量',style: TextStyle(color: Colors.white,fontSize: 6.sp),)
                        ],
                      ),
                    )
                  ],
                )
            ),
            if(showFaceAuth)...[
              Positioned(left:130.w,top:87.h,
                child: InkWell(
                    onTap: (){
                      callback();
                    },
                    child: Obx(() => isEmpty.value?
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text("人脸登陆:已注册  ",style: TextStyle(color: Colors.blue,fontSize: 10.sp),),
                        Image.asset("assets/images/camera_change.png",width: 34.w,fit: BoxFit.fitWidth,),
                      ],
                    ):
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text("人脸登陆:未注册  ",style: TextStyle(color: Colors.blue,fontSize: 10.sp),),
                        Image.asset("assets/images/camera_register.png",width: 34.w,fit: BoxFit.fitWidth,),
                      ],
                    ),
                    )
                ),
              ),
            ]

          ],
        )
    );
  }

}

